
require"girl/init"
require"terrain/init"

local title = nil;

gm = nil;
graph = Girl.Graphics();
idle = Girl.Idle(1/100);

function love.load(argv)
	require"terrain_toy"
	require"ui"

	title = love.graphics.getCaption();
	
	graph:createImageFromPath("wndbg","img/wnd.png");
	graph:createImageFromPath("normal","img/normal.png");
	graph:createImageFromPath("click","img/click.png");
	graph:createFontFromSize("font10",10);
	graph:createFontFromSize("font12",12);
	graph:createFontFromSize("font24",24);
	
	graph._setBackgroundColor({150,150,150});
	
	gm = Girl.GuiManager();
	
	gm:add(HeightMapOptionWnd(graph));
	gm:add(GenDiamondWnd(graph))
	gm:add(TerrainWnd(graph))
	gm:add(TerrainOptionWnd(graph))
	gm:add(PerlinOption(graph))
	gm:add(GenPerlinWnd(graph))
	
	gm:topMost("HeightMapOption");
	
	local file = nil;
	local autoresize = false;
	for i, v in pairs(argv) do
		if v=="--f" then
			file = argv[i+1];
		elseif v=="--autoresize" then
			autoresize = true;
		end
	end
	if file then
		LoadHeightmapFile(file, autoresize);
	end
end

function love.update(dt)
	love.graphics.setCaption(title..' [FPS: '..love.timer.getFPS()..']');
	
	idle:tic(dt);
	gm:update(dt);
end

function love.draw()
	graph:setFont("font24");
	love.graphics.setColor({50,50,50})
	love.graphics.print("Terrain Toy 0.1", 5, love.graphics.getHeight()-30);
	graph:setFont();
	graph:setFont("font12");
	love.graphics.print("write by xerysherry", 200, love.graphics.getHeight()-20);
	graph:setFont();

	gm:draw();
end	

function love.mousepressed(x, y, button)
	gm:mousepressed(x, y, button);
end

function love.mousereleased(x, y, button)
	gm:mousereleased(x, y, button);
end

function love.keypressed(key, unicode)
	gm:keypressed(key, unicode);
end

function love.keyreleased(key)
	gm:keyreleased(key);
end